//
//  CRSpace.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/21.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRSpace.h"

@implementation CRSpace

+ (instancetype)spaceWithDict:(NSDictionary *)dict
{
    CRSpace *space = [[CRSpace alloc] init];
    [space setValuesForKeysWithDictionary:dict];
    return space;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"pics"]) {
        self.picurl = value[@"url"];
        NSLog(@"%@", self.picurl);
    }
}

- (instancetype)spaceWithAvobject:(AVObject *)obj
{
    self.objectId = obj[@"objectId"];
    // 发送的内容
    self.content = obj[@"content"];
    // 发送的图片
    AVFile *pics = [obj objectForKey:@"pics"];
    self.picurl = pics.url;
    // 创建时间
    NSDate *date = obj[@"createdAt"];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MM-dd HH:mm";
    NSString *str = [formatter stringFromDate:date];
    self.timeLabel = str;
    // 地址信息
    self.address = obj[@"address"];
    // 用户的昵称
    self.nickName = obj[@"username"];
    // 用户的头像的地址
    self.iconUrl = obj[@"iconUrl"];
    // 该条空间的评论人的username
    self.praiseInfo = obj[@"praiseInfo"];
    // 赞的个数
    self.likeCount = [obj[@"likeCount"] intValue];
    // 不攒的个数
    self.noLickCount = [obj[@"noLickCount"] intValue];
    // 分享的个数
    self.shareCount = [obj[@"shareCount"] intValue];
    return self;

}
+ (instancetype)spaceWithAvobject:(AVObject *)obj
{
    return [[self alloc] spaceWithAvobject:obj];
}

@end





